package com.cskt.petums.handler;
import com.cskt.common.exception.BaseException;
import com.cskt.common.entity.vo.ResultVO;
import com.cskt.common.entity.vo.StatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理器
 *
 * @author admin
 * @date 2023/04/14 18:40
 **/
@RestControllerAdvice
public class ExceptionAdvice {

    private static final Logger log = LoggerFactory.getLogger(ExceptionAdvice.class);

    @ExceptionHandler(value = BaseException.class)
    public ResultVO<Void> baseExceptionHandler(BaseException ex) {
        log.error("统一异常信息：{}",ex.getErrorMsg());
        return ResultVO.error(ex.getStatusEnum());
    }

    @ExceptionHandler(value = RuntimeException.class)
    public ResultVO<Void> runtimeExceptionHandler(RuntimeException ex) {
        log.error("运行时异常：{}", ex.getMessage());
        return ResultVO.error(StatusEnum.COMMON_EXCEPTION.getCode(), ex.getMessage());
    }

}
